package com.hao.DaoImpl;
import  com.hao.Dao.userDao;
import com.hao.entity.user;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.hao.util.BaseDao;

/**
 * Created by Administrator on 2018/8/6.
 */
        public class userImpl implements  userDao {


    @Override
    public List<user> finduser(int uid) {
        List<user> list=new ArrayList<user>();
        String sql="SELECT * FROM user where 1=1 ";
        if (uid!=-1) {
            sql+=" and uid=?";
        }
        Connection conn=null;
        PreparedStatement state=null;

        ResultSet rs=null;
        try {
            conn=BaseDao.getConnection();
            state=conn.prepareStatement(sql);
            if(uid!=-1) {
                state.setInt(1, uid);
            }
            rs=state.executeQuery();
            while(rs.next()){
               user  pp=new user();
               pp.setUid(rs.getInt("uid"));
                pp.setUname(rs.getString("uname"));
                list.add(pp);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            BaseDao.closeConnection(conn, state, rs);
        }
        return list;
    }
}
